CI/CD Coverage Enforcement
**Phase:** 35 Plan 06
**Status:** ā Configured
**Last Updated:** 2026-02-15
Overview
The platform has automated coverage enforcement via GitHub Actions that runs on every pull request and push to main branch. This ensures code coverage never regresses below established thresholds.
Coverage Thresholds
Frontend (Vitest)
- **Overall:** 80% lines, functions, statements; 70% branches
- **Brain Systems (
src/lib/ai):** 90% lines, functions, statements; 80% branches - **Integrations (
src/lib/integrations):** 85% lines, functions, statements; 75% branches
Backend (pytest)
- **Overall:** 80% coverage
- **Critical Files:** 90% coverage (episode service, graduation exam, governance)
GitHub Actions Workflows
1. Coverage Enforcement Workflow
**File:** .github/workflows/coverage.yml
**Triggers:**
- Pull requests to
mainbranch - Pushes to
mainbranch
**Jobs:**
Frontend Coverage
- Runs
npm run test:coverage - Enforces 80% threshold (fails CI if below)
- Checks brain system files for 90% threshold
- Generates JSON, HTML, and lcov reports
Backend Coverage
- Runs
pytestwith--cov=core --cov=api - Enforces 80% threshold (fails CI if below)
- Generates JSON and terminal reports
Coverage Report
- Combines frontend and backend coverage
- Comments on PR with coverage summary
- Shows coverage vs target comparison
- Indicates pass/fail status
Status Badge
- Updates coverage badge on push to main
- Stores badge artifact for 90 days
- Color-coded: green (ā„80%), yellow (ā„60%), red (<60%)
2. Test Coverage Workflow
**File:** .github/workflows/test-coverage.yml
**Features:**
- Uploads coverage to Codecov (optional)
- Generates combined coverage reports
- Uploads HTML reports as artifacts
- Shows coverage targets in GitHub summary
PR Coverage Comments
Every PR automatically receives a coverage comment:
## š Coverage Report
### Frontend
| Metric | Coverage | Target |
|--------|----------|--------|
| Lines | 82.5% | 80% |
| Functions | 78.3% | 75% |
| Branches | 72.1% | 70% |
| Statements | 81.2% | 80% |
**Status:** ā
Meets 80% threshold
### Backend
**Overall Coverage:** 85.2%
**Status:** ā
Meets 80% threshold
---
*This comment is automatically generated by the coverage enforcement workflow.*Coverage Badges
Badges displayed in README.md:
[](...)
[](...)
[](...)CI/CD Enforcement Behavior
On Pull Request
- **Coverage Check Runs:**
- Frontend coverage job starts
- Backend coverage job starts
- Both run in parallel
- **Threshold Enforcement:**
- If coverage < 80%: ā CI fails, PR cannot merge
- If coverage ā„ 80%: ā CI passes, PR can merge
- **PR Comment:**
- Automatic coverage summary posted
- Shows pass/fail for each metric
- Includes coverage vs target comparison
- **Status Checks:**
- "Frontend Coverage (80%)" must pass
- "Backend Coverage (80%)" must pass
- Both required for merge
On Push to Main
- **Coverage Check Runs:**
- Same as PR check
- **Badge Update:**
- Coverage badge updated with latest percentage
- Badge color changes based on coverage level
- **Report Storage:**
- Coverage reports stored as artifacts (30-90 days)
- HTML reports available for download
Running Coverage Locally
Frontend Coverage
# Run coverage with report
npm run test:coverage
# Open HTML report
npm run coverage:report
# Check specific file coverage
npx vitest run --coverage --reporter=verbose src/lib/ai/cognitive-architecture.tsBackend Coverage
# Run coverage with report
cd backend-saas
pytest --cov=core --cov=api --cov-report=html --cov-report=term-missing
# Open HTML report
open htmlcov/index.html
# Check specific module coverage
pytest --cov=core.episode_service --cov-report=term-missingTroubleshooting
CI Fails with "Coverage below threshold"
**Cause:** New code reduced coverage below 80% (or tier-specific threshold)
**Solution:**
- Check the PR comment for specific metrics that failed
- Add tests for uncovered code paths
- If decrease is intentional (e.g., removing dead code):
- Update tests to cover new code
- Document why coverage decreased
- Get team approval before merging
Coverage Report Not Generated
**Cause:** Test failures prevent coverage generation
**Solution:**
- Fix failing tests first
- Coverage report generates only when all tests pass
- Use
--no-coverageflag to run tests without coverage:
npm run test:coverage -- --no-coverageBrain System Threshold Failure
**Cause:** AI system files below 90% coverage
**Solution:**
- Check which brain system file failed the threshold
- Review HTML coverage report for uncovered lines
- Add tests for uncovered functions/branches
- Core brain systems (cognitive, learning, world model) need 95%
Backend Coverage Fails
**Cause:** Backend coverage below 80%
**Solution:**
- Check backend coverage report:
backend-saas/coverage.json - Identify modules with low coverage
- Add unit tests for critical backend files
- Focus on: episode service, graduation exam, governance, business intelligence
Coverage Reports
Artifacts (GitHub Actions)
After each CI run, coverage reports are stored as artifacts:
- **frontend-coverage:** JSON and HTML reports
- **backend-coverage:** JSON and HTML reports
- **coverage-summary:** Combined markdown summary
- **coverage-badge:** Badge JSON for README
Local Reports
- **Frontend:**
coverage/index.html - **Backend:**
backend-saas/htmlcov/index.html - **Frontend JSON:**
coverage/coverage-summary.json - **Backend JSON:**
backend-saas/coverage.json
Coverage Trends
To track coverage over time:
- Check badge in README for current coverage
- Review PR comments for coverage changes
- Download artifacts from GitHub Actions for historical data
- Use Codecov (if configured) for trend visualization
Best Practices
- **Write Tests First:** TDD approach ensures coverage from the start
- **Check Coverage Locally:** Run
npm run test:coveragebefore pushing - **Review PR Comments:** Check coverage summary before merging
- **Fix Coverage Drops:** Don't merge PRs that reduce coverage
- **Focus on Critical Code:** Brain systems and governance need highest coverage
- **Document Exceptions:** If coverage must decrease, document why and how to fix
Configuration Files
- **Frontend:**
vitest.config.ts(thresholds, report directories, per-file thresholds) - **Backend:**
pytest.iniandpyproject.toml(coverage settings, thresholds) - **CI/CD:**
.github/workflows/coverage.yml(enforcement, PR comments, badges) - **Codecov:**
.github/workflows/test-coverage.yml(optional upload to Codecov)
Related Documentation
Success Criteria
ā **All criteria met:**
- [x] GitHub Action workflow created for coverage checks
- [x] PR checks fail if coverage < 80%
- [x] Coverage reports commented on PRs
- [x] Coverage badges added to README
- [x] CI/CD enforcement tested and working
- [x] Documentation created
Next Steps
- **Monitor Coverage:** Watch PR comments for coverage trends
- **Fix Failures:** Address coverage drops immediately
- **Incremental Improvement:** Gradually increase thresholds (80% ā 85% ā 90%)
- **Report Generation:** Run full coverage report after each phase
- **Badge Updates:** Badges auto-update on push to main
---
**Phase 35 Status:** Coverage enforcement configured and active. All PRs must meet 80% threshold to merge.